<%@ page import="java.util.List" %>
<%@ page import="com.xinjie.www.po.Post" %>
<%@ page import="com.xinjie.www.util.Constants" %>
<%@ page import="com.xinjie.www.po.User" %>
<%@ page import="com.xinjie.www.service.post.PostServiceImpl" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查看自己发布的贴子</title>
    <style type="text/css">
        table {
            width: 100%;
            border: 1px solid red;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<%
    PostServiceImpl postService = new PostServiceImpl();
    Object o = request.getSession().getAttribute(Constants.USER_SESSION);
    User user = (User) o;
    List<Post> posts = null;
    try {
        posts = postService.getOwnPost(user.getUserName());
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
%>
<div align="center">
    <h4>已发布的帖子</h4>
    <table>
        <tr>
            <th>贴子id</th>
            <th>主题</th>
            <th>所属贴吧</th>
            <th>内容</th>
            <th>评论数</th>
            <th>点赞数</th>
            <th>发布时间</th>
            <th></th>
            <th></th>
        </tr>
        <%
            for (Post post : posts) {
        %>
        <tr>
            <%= "<td>" + post.getPostId() + "</td>"%>
            <%="<td>" + post.getTitle() + "</td>"%>
            <%="<td>" + post.getTieba() + "</td>"%>
            <%="<td>" + post.getContent() + "</td>"%>
            <%="<td>" + post.getComment() + "</td>"%>
            <%="<td>" + post.getThumb() + "</td>"%>
            <%="<td>" + post.getTime() + "</td>"%>
            <%
                String s = post.getPostId() + "";
                String s1 = post.getTieba();
            %>
            <td><a href="PostCommentList.jsp?PostId=<%=s%>">管理评论</a> </td>
            <td><a href="DeletePost.jsp?id=<%=s%>&tiebaName=<%=s1%>">删除</a></td>
        </tr>
        <%}%>
    </table>
    <a href="UserFrame.jsp">返回</a>
    <%if (request.getSession().getAttribute("deletePostSuccess") != null) {%>
    <%=request.getSession().getAttribute("deletePostSuccess")%>
    <%request.getSession().removeAttribute("deletePostSuccess");%>
    <%
        }
        if (request.getSession().getAttribute("deletePostLose") != null) {
    %>
    <%=request.getSession().getAttribute("deletePostLose")%>
    <%request.getSession().removeAttribute("deletePostLose");%>
    <%}%>
    <%if (request.getSession().getAttribute("deleteSuccess") != null) {%>
    <%=request.getSession().getAttribute("deleteSuccess")%>
    <%request.getSession().removeAttribute("deleteSuccess");%>
    <% }if (request.getSession().getAttribute("deleteLose")!=null){%>
    <%=request.getSession().getAttribute("deleteLose")%>
    <%request.getSession().removeAttribute("deleteLose");%>
    <%}%>
</div>
</body>
</html>
